//
//  SignInView.m
//  项目三
//
//  Created by rimi1 on 2016/11/30.
//  Copyright © 2016年 Wangxingqian. All rights reserved.
//

#import "SignInView.h"

static NSInteger spacing_ = 20;

@implementation SignInView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.logoImage];
        [self addSubview:self.account];
        [self addSubview:self.password];
        [self addSubview:self.signInButton];
        [self addSubview:self.enrollButton];
        [self addSubview:self.forgetPassword];
    }
    return self;
}

#pragma mark - respondsTo...

- (void)respondsToButton:(UIButton *)sender {
    [self.delegate signInView:self tapOfButton:sender];
}

- (UITextField *)textFieldWithRect:(CGRect)rect placeholder:(NSString *)placeholder {
    UITextField *text = [[UITextField alloc] initWithFrame:rect];
    text.clearButtonMode = UITextFieldViewModeWhileEditing;
    text.placeholder = placeholder;
    text.textAlignment = NSTextAlignmentCenter;
    text.keyboardType = UIKeyboardTypeASCIICapable;
    
    CGFloat height = 1.5;
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, text.bounds.size.height - height, text.bounds.size.width, height)];
    view.backgroundColor = [UIColor lightGrayColor];
    [text addSubview:view];
    
    return text;
}

#pragma mark - get

- (UIImageView *)logoImage {
    
    if (!_logoImage) {
        
        _logoImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kWIDTH, kHEIGHT)];
        _logoImage.image = [UIImage imageNamed:@"登录背景"];
        
    }
    return _logoImage;
}

- (UITextField *)account {
    
    if (!_account) {
        
        _account = [self textFieldWithRect:CGRectMake(0, WXQAdaptionHeight(270), kWIDTH, 44) placeholder:@"请输入账号"];
        
    }
    return _account;
}

- (UITextField *)password {
    
    if (!_password) {
        
        _password = [self textFieldWithRect:CGRectMake(CGRectGetMinX(self.account.frame), CGRectGetMaxY(self.account.frame) + spacing_, CGRectGetWidth(self.account.bounds), CGRectGetHeight(self.account.bounds)) placeholder:@"请输入密码"];
        _password.secureTextEntry = YES;
        _password.clearsOnBeginEditing = YES;
        
    }
    return _password;
}

- (UIButton *)signInButton {
    
    if (!_signInButton) {
        
        _signInButton = [[UIButton alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.password.frame) + 2 * spacing_, WXQAdaptionWidth(300), 55)];
        CGPoint point = _signInButton.center;
        point.x = kWIDTH/2;
        _signInButton.center = point;
        _signInButton.backgroundColor = [UIColor orangeColor];
        _signInButton.layer.cornerRadius = 10;
        [_signInButton setTitle:@"登录" forState:UIControlStateNormal];
        _signInButton.tag = 101;
        [_signInButton addTarget:self action:@selector(respondsToButton:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _signInButton;
}

- (UIButton *)enrollButton {
    
    if (!_enrollButton) {
        
        _enrollButton = [[UIButton alloc] initWithFrame:CGRectMake(kWIDTH - 80, kHEIGHT - 64, 60, 44)];
        [_enrollButton setTitle:@"注册" forState:UIControlStateNormal];
        _enrollButton.tag = 102;
        [_enrollButton addTarget:self action:@selector(respondsToButton:) forControlEvents:UIControlEventTouchUpInside];
        [_enrollButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        
    }
    return _enrollButton;
}

- (UIButton *)forgetPassword {
    
    if (!_forgetPassword) {
        
        _forgetPassword = [[UIButton alloc] initWithFrame:CGRectMake(spacing_, kHEIGHT - 64, 100, 44)];
        [_forgetPassword setTitle:@"忘记密码" forState:UIControlStateNormal];
        _forgetPassword.tag = 103;
        [_forgetPassword addTarget:self action:@selector(respondsToButton:) forControlEvents:UIControlEventTouchUpInside];
        [_forgetPassword setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        
    }
    return _forgetPassword;
}

@end














